package cn.jcet.gumall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.jcet.gumall.ware.vo.PurchaseDataVo;
import cn.jcet.gumall.ware.vo.PurchaseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.jcet.gumall.ware.entity.PurchaseEntity;
import cn.jcet.gumall.ware.service.PurchaseService;
import cn.jcet.common.utils.PageUtils;
import cn.jcet.common.utils.R;



/**
 * 采购信息
 *
 * @author coder_yang
 * @email 1546656922@qq.com
 * @date 2020-06-28 21:41:04
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;


    /**
     * /ware/purchase/done
     * 完成采购
     */
    @PostMapping("/done")
    public R donePurchase(@RequestBody PurchaseDataVo purchaseDataVo){

        this.purchaseService.done(purchaseDataVo);

        return R.ok();
    }

    /**
     * /ware/purchase/received
     * 领取采购单
     * @param ids
     * @return
     */
    @PostMapping("/received")
    public R receivedPurchase(@RequestBody List<Long> ids){

        this.purchaseService.receivedPurchase(ids);


        return R.ok();
    }


    ///ware/purchase/merge
    @PostMapping("/merge")
    public R mergePurchase(@RequestBody PurchaseVo purchaseVo){
        this.purchaseService.saveMergePurchase(purchaseVo);

        return R.ok();
    }


    // /ware/purchase/unreceive/list
    @RequestMapping("/unreceive/list")
    public R unreceiveList(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPageUnreceiveByPurchase(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
